// 国际化数据格式化执行文件
const fs = require("fs");
const JsPath = __dirname.replace("config", "") + "languages/modules";
import { langs } from "../languages/modules/index";

const fsWrite = function () {
	const lg: any = {};
	const keys = Object.keys(langs);
	for (let i = 0; i < keys.length; i++) {
		Object.keys(langs[keys[i]]).forEach(item => {
			if (!lg.hasOwnProperty(item)) {
				lg[item] = {};
			}
			lg[item][keys[i]] = langs[keys[i]][item];
		});
	}
	Object.keys(lg).forEach(item => {
		const str = "export default" + " " + JSON.stringify(lg[item], null, "\t") + ";\n";
		fs.writeFile(JsPath + `/${item}.ts`, str, function (error: any) {
			if (error) {
				return false;
			}
			console.log(`写入成功${item}.ts`);
		});
	});
};
export default fsWrite;
